package com.my.interview.lock;

import java.util.concurrent.locks.ReentrantLock;


/**
 * 可重入锁 ReentrantLock
 */
public class ReentrantLockTest implements Runnable {

    ReentrantLock lock = new ReentrantLock();

    private void get(){

        lock.lock();
        System.out.println(Thread.currentThread().getId());
        set();
        lock.unlock();
    }

    private void set(){

        lock.lock();
        System.out.println(Thread.currentThread().getId());
        lock.unlock();
    }

    @Override
    public void run() {
        get();
    }

    public static void main(String[] args) {
        ReentrantLockTest test = new ReentrantLockTest();
        new Thread(test).start();
        new Thread(test).start();
        new Thread(test).start();
    }
}
